package cn.plushine.service;

import cn.plushine.mapper.IndexMapper;
import cn.plushine.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    IndexMapper indexMapper;

    // 用户登录
    @Override
    public User login(String username, String password) throws Exception {
        // 调用dao层接口，查询数据库
        User userDB = indexMapper.login(username, password);
        // 查询结果为空
        if (userDB != null) {
            return userDB;
        }
        // 抛出异常
        throw new Exception("登录失败，请检查用户名和密码是否正确！");
    }

    // 获取用户信息
    @Override
    public User info(int id) throws Exception {
        User infoDB = indexMapper.info(id);
        if (infoDB != null) {
            return infoDB;
        }
        // 抛出异常
        throw new Exception("获取用户信息失败！");
    }

}
